// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of Ubiquity formsPlayer
//
// Ubiquity formsPlayer is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// Ubiquity formsPlayer is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with Ubiquity formsPlayer If not, see <http://www.gnu.org/licenses/>.
//	
//
//   Purpose: declaration of CImplBind.
//   $Id$


#pragma once
#include "formcontrol.h"
#include "INodeset.h"

class CVertexList;
class CVertex;
class CImplNodeBinding;

class CImplBind 
	:public CImpl
	,public INodeset
{
	friend class CXFormsParseBind;
	//HACK: to allow bind and setvalue to work.
	//	in the future, this won;t be needed, as bind will
	//	work directly with the setvalue object, rather 
	//	than the method in CImplModel.
	friend class CImplModel;
	//HACK: as above, but for submission
	friend class CImplSubmitInfo;
public:
	virtual void notifyDelete();
	CImplBind(CImplModel * pMod);
	virtual ~CImplBind(); 

	virtual HRESULT init();

	void AddToGraph(CVertexList * pGraph,IXMLDOMNode * pContext = 0);
	void AddBind(CImplBind * pBind);
	void AddControl(CImplNodeBinding * pControl);
	bool RemoveControl(CImplNodeBinding * pControl);
	//<summary>
	//	Within the nodeset represented by this object, returns the node with index lIndex
	//	The first item in the nodeset is item 0.
	//</summary>
	//<returns>
	//	S_OK if that node exists;<br />
	//	S_FALSE if the index is out-of-range.
	//</returns>
	virtual HRESULT GetNodeAt(const long lIndex, IXMLDOMNode **ppRetval);
	virtual long GetNodesetLength();
private:

	CComBSTR m_sType;
	CComBSTR m_sReadOnly;
	CComBSTR m_sRequired;
	CComBSTR m_sRelevant;
	CComBSTR m_sConstraint;
	CComBSTR m_sCalculate;
	CComBSTR m_sRef;

	CTypedPtrList<CPtrList,CImplBind*> m_childBinds;
	CTypedPtrList<CPtrList,CImplNodeBinding*> m_controls;
	CTypedPtrArray<CPtrArray,CVertex*> m_instVertices;

	// rebuilds m_instVertices
	void rebuildTargetNodeset(IXMLDOMNode * pContext,CIdResolver * pResolver);
	// fetches m_pType.
	HRESULT fetchType();
	ISchemaType * m_pType;
};